<%@ page contentType="text/html;charset=utf-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>便民服务平台3.0</title>
</head>

<body>
<jsp:include page="../include/header.jsp"/>

<div class="matters-container">
    <div class="mc-hd">

    	<p class="mc-hd-t">BUSINESS SERVICES</p>
        <ul class="mc-category">
        	<li id="JZ"><a href="#" onclick="javascript:caseGroup('JZ');" >警种服务</a></li>
            <li id="GR"><a href="#" onclick="javascript:caseGroup('GR');" >个人服务</a></li>
            <li id="QY"><a href="#" onclick="javascript:caseGroup('QY');" >企业服务</a></li>
            <li id="SS"><a href="#" onclick="javascript:caseGroup('SS');" >搜索服务</a></li>
        </ul>
        <div class="type-wrap">
        	<h2 class="typedH2">慧眼看世界，在政务服务的路上不断追求创新！</h2>
        </div>

    </div>
    <div class="mc-bd">
        <div class="mcc-search" style="display: none;">
            <div class="input-group">
                <input id="caseKeywords" value="" type="text" class="form-control" placeholder="请输入您要查找的关键词">
                <span class="input-group-btn">
                    <button class="btn btn-green" onclick="javascript:callBackPagination('');" type="button">事项搜索</button>
                </span>
            </div>
        </div>
        <ul class="mcc-menus">

        </ul>

            <div class="container" id="mainContent" >


            </div>
        <div style="text-align: center"><div id="callBackPager" class="pagination" style="margin: 0 auto;"></div></div>

    </div>
</div>

<jsp:include page="../include/footer.jsp"/>
<script src="<c:url value='/resource/js/require.js'/>" data-main="<c:url value='/resource/js/main.js'/>"  id="current-page" current-page ="mattersCenter"></script>
<script src="<c:url value='/resource/js/jquery-1.9.1.min.js'/>"></script>
<script src="<c:url value='/resource/js/jqPaginator.js'/>"></script>
<script type="text/javascript">

	$(function(){
        caseGroup('JZ');
	});

    function caseGroup(type){
        var caseType = "";
        $("#"+type+" a").addClass("active");
        $("#"+type).siblings().each(function(){
            $(this).children("a").removeClass("active");
        });

        if(type=="SS"){
            $(".mcc-search").show();
            $(".mcc-menus").hide();
            callBackPagination(caseType);
        }else {
            $(".mcc-search").hide();
            $("#caseKeywords").val("");
            $(".mcc-menus").show();
            $.ajax({
                url: '<c:url value="/matters/case-catalog"></c:url>',
                data : {"type" : type},
                dataType: "json",
                success: function (resp) {

                    var lis = "";
                    for (var i = 0; i < resp.data.length; i++) {
                        if(i == 0){
                            lis += "<li class=\"active\"><a onclick=\"callBackPagination('"+resp.data[i].id+"');\" id="+resp.data[i].id+" href=\"#\">" + resp.data[i].value + "</a></li>";
                        }else {
                            lis += "<li><a onclick=\"callBackPagination('"+resp.data[i].id+"');\" id="+resp.data[i].id+" href=\"#\">" + resp.data[i].value + "</a></li>";
                        }
                    }
                    $(".mcc-menus").children().remove();
                    $(".mcc-menus").append(lis);
                    caseType = $(".mcc-menus li:first-child").children("a").attr("id");
                    callBackPagination(caseType);
                }
            });
        }


    }

    function callBackPagination(caseType) {
        var caseKeywords = $("#caseKeywords").val().trim();
        $('#mainContent').empty();
        if(caseType != undefined && caseType!=""){
            $("#"+caseType).parent().addClass("active");
            $("#"+caseType).parent().siblings().removeClass("active");
        }else if(caseType == undefined){
            $('#callBackPager').empty();
            return;
        }

        var limit = 8;
        var currPage = 1;
        var keywords = "";
        if(caseKeywords != undefined){
            keywords = caseKeywords;
        }

        getList(currPage,limit,caseType,keywords);

    }

    function getList(pi,ps,typeId,kw){
        console.info(1);
        $.ajax({
            url:'<c:url value="/matters/case-list"></c:url>',
            type:"post",
            data : {"ps" : ps,"pi":pi,"typeId":typeId,"kw":kw},
            dataType:"json",
            success:function(resp){

                if(resp.succ){
                    var html = [];
                    html.push(' <div class="container">');
                    html.push(' <div class="row">');

                    if(resp.data.list.length == 0){
                        layer.open({
                            content: '暂无相关事项',
                            scrollbar: false
                        });
                    }

                    for (var i = 0; i < resp.data.list.length; i++) {
                        html.push('<div class="col-sm-3">');
                        html.push('<div class="matter-cell">');
                        if(resp.data.list[i].isHot=="1"){
                            html.push('<i class="cell-hot"></i>');
                        }else{
                            html.push('<i></i>');
                        }
                        if(resp.data.list[i].matName.length > 16){
                            var matName = resp.data.list[i].matName.substring(0,16);
                            html.push('<div class="matter-cell-hd"><h3 title="'+resp.data.list[i].matName+'">'+matName+'</h3></div>');
                        }else{
                            html.push('<div class="matter-cell-hd"><h3 title="'+resp.data.list[i].matName+'">'+resp.data.list[i].matName+'</h3></div>');
                        }

                        var guide = resp.data.list[i].guide;
                        if(guide==null){
                            guide="<p>暂无办事指南</p>";
                        }else if(guide.length >40){
                            guide = guide.substring(0,40);
                        }
                        html.push("<div class=\"matter-cell-bd\"><h5>办事指南</h5>"+guide+"</div>");
                        //html.push('<div class="matter-cell-bd"><h5>办事指南</h5><p>'+resp.data.list[i].guide+'</p></div>');
                        html.push('<div class="matter-cell-ft">');
                        html.push("<a href=\"javascript:loadMattersDetail('"+resp.data.list[i].guid+"')\" id=\""+resp.data.list[i].guid+"\" class=\"btn btn-block btn-blue\">详情</a>");
                        if(resp.data.list[i].matApplyStatus == "Y"){
                            if(resp.data.list[i].applyUrl == "LOCALHOST"){
                                html.push("<a href='javascript:to_apply(\""+resp.data.list[i].guid+"\")' class=\"btn btn-block btn-yellow\">申报</a>");
                            }else {
                                html.push("<a href='javascript:to_thirdApply(\""+resp.data.list[i].applyTarget+"\",\""+resp.data.list[i].applyUrl+"\")' class=\"btn btn-block btn-yellow\">申报</a>");
                            }
                        }
                        if(resp.data.list[i].matReserveStatus == "Y"){

                            if(resp.data.list[i].reserveUrl == "LOCALHOST"){
                                html.push("<a href=\"#\" class=\"btn btn-block btn-green\">预约</a>");
                            }else {
                                html.push("<a href='javascript:to_thirdReserve(\""+resp.data.list[i].reserveTarget+"\",\""+resp.data.list[i].reserveUrl+"\")' class=\"btn btn-block btn-green\">预约</a>");
                            }
                        }

                        html.push('</div></div></div>');
                    }
                    html.push('</div></div>');
                    var mainObj = $('#mainContent');
                    mainObj.empty();
                    mainObj.html(html.join(''));

                    $("#callBackPager").jqPaginator({
                        totalPages: resp.data.totalPage==0?1:resp.data.totalPage,
                        visiblePages: 10,
                        currentPage: pi,
                        pageSize: ps,
                        onPageChange: function (n,type) {
                            if(type=='change'){
                                getList(n, ps,typeId,kw);
                            }
                        }
                    });

                }else{
                    toast(resp.msg);
                }
            },
            error:function(res){


                toast(res.msg);
            }
        });
    }

    function loadMattersDetail(caseGuid){
        $("#mainContent").html("");
        $('#callBackPager').empty();
        $("#mainContent").load('<c:url value="/matters/detail/"/>'+caseGuid);

    }
    function to_apply(guid){
        var consultant='${current_member.guid}';
        if(consultant==''){
            $(".login-a").trigger('click');
            return;
        }
        $("#mainContent").html("");
        $('#callBackPager').empty();
        $("#mainContent").load('<c:url value="/matters/apply?caseGuid="/>'+guid);
        <%--window.location.href="<c:url value='/matters/apply?caseGuid='/>"+guid;--%>
    }
    function to_thirdApply(applyTarget,applyUrl){
        if(applyTarget=="BLANK"){
            window.location.href=applyUrl;
        }else {

            $("#mainContent").html("<Iframe src=\""+applyUrl+"\"; scrolling=\"yes\" width=\"100%;\" height=\"498px;\" frameborder=\"0\"></iframe>");
            $('#callBackPager').empty();
            //$("#mainContent").load(applyUrl);
        }
    }
    function to_thirdReserve(reserveTarget,reserveUrl){
        if(reserveTarget=="BLANK"){
            window.location.href=reserveUrl;
        }else {
            $("#mainContent").html("<Iframe src=\""+reserveUrl+"\"; scrolling=\"yes\" width=\"100%;\" height=\"498px;\" frameborder=\"0\"></iframe>");
            $('#callBackPager').empty();
            //$("#mainContent").load(reserveUrl);
        }
    }
    function showTemplate(guid,type){
        $.ajax({
            url: '<c:url value="/matters/case-manifest"></c:url>',
            data : {"guid":guid,"type" : type},
            dataType: "json",
            success: function (resp) {
                $(".modal-content").html("");
                $(".modal-content").append("<img src=\"data:image/png;base64,"+resp.data+"\"/>");
                $('.f-preview').modal();
            }
        });
    }

    function downloadTable(guid,type){
        window.location.href = '<c:url value="/matters/ajax-download"/>'+"?guid="+guid+"&type="+type;
    }
</script>
<script>
    $(".mcc-menus>li a").click(function(){
        if( $(this).html()==="交管"){
            $(this).removeProp("onclick").prop({"href":"http://hl.122.gov.cn/","target":"_blank"});
        }
    });
</script>

<script>

    function loadSecondDept(matNum){
        var val = $("#firstDept").val();
        var canApply =  $("#firstDept").find("option:selected").attr("data-canApply");
        var $secondDept = $("#secondDept");
        $("#thirdDept").hide();
        $secondDept.empty();
        $.ajax({
            url: '<c:url value="/matters/ajax-mattersDept"></c:url>',
            type:"get",
            data : {"matNum" : matNum,"deptId":val,"lev":"38"},
            dataType: "json",
            success: function (resp) {
                if(resp.length>0){
                    $secondDept.show();
                    $secondDept.append("<option value=''>--请选择--</option>");
                    $.each(resp, function(index,element){
                        var deptName = element.deptName;
                        deptName = element.canApply == 1 ? deptName+"(可选)" : deptName;
                        $secondDept.append("<option value='"+ element.deptId +"' data-canApply='"+ element.canApply +"'>"+ deptName + "</option>");
                    })
                }else{
                    $secondDept.hide();
                }
            }
        })
    }

    function loadThirdDept(matNum){
        var val = $("#secondDept").val();
        var canApply =  $("#secondDept").find("option:selected").attr("data-canApply");
        var $thirdDept = $("#thirdDept");
        $thirdDept.empty();
        $.ajax({
            url: '<c:url value="/matters/ajax-mattersDept"></c:url>',
            type:"get",
            data : {"matNum" : matNum,"deptId":val,"lev":"51"},
            dataType: "json",
            success: function (resp) {
                if(resp.length>0){
                    $thirdDept.show();
                    $thirdDept.append("<option value=''>--请选择--</option>");
                    $.each(resp, function(index,element){
                        var deptName = element.deptName;
                        deptName = element.canApply == 1 ? deptName+"(可选)" : deptName;
                        $thirdDept.append("<option value='"+ element.deptId +"' data-canApply='"+ element.canApply +"'>"+ deptName + "</option>");
                    })
                }else{
                    $thirdDept.hide();
                }
            }
        });
    }

    //删除附件
    function deleteFlie(e,guid){
        $.ajax({
            url: '<c:url value="/matters/ajax-att/"/>'+guid,
            type:"DELETE",
            dataType: "json",
            success: function (resp) {
                if(resp.succ){
                    $(e).parent().remove();
                }else{
                    toast("删除附件失败");
                }
            },
            error:function(res){
                toast("删除附件失败");
            }
        })
    }

    var deptId = "";
    function validApplyInfo(){
        deptId=$('#thirdDept').val();
//        var canApply=$('#thirdDept').find("option:selected").attr("data-canApply");
        if(deptId==''||deptId==null){
            deptId=$('#secondDept').val();
//            canApply=$('#secondDept').find("option:selected").attr("data-canApply");
        }
        if(deptId==''||deptId==null){
            deptId=$('#firstDept').val();
//            canApply=$('#firstDept').find("option:selected").attr("data-canApply");
        }

        if(deptId==''||deptId==null){
            layer.open({
                content: '请选择受理公安机关',
                scrollbar: false
            });
            return ;
        }
        var isAttRequred = true;
        $(".attRequredY").each(function(){
            if($(this).siblings().length <= 1){
                isAttRequred = false;
            }
        });
        if(!isAttRequred){
            layer.open({
                content: '请上传必传附件',
                scrollbar: false
            });
            return;
        }
        $('#chooseWay-dialog').modal();
    }

    //提交申报
    function mattersSubmit(matNum,acountId) {
        var consultant='${current_member.guid}';
        if(consultant==''){
            $(".login-a").trigger('click');
            return;
        }

//        if(canApply==0){
//            toast("选择的公安机关不可选");
//            return ;
//        }


        //事项编号非Guid matNum
        //登录账户  acountId
        //联系地址
        var linkAddress = $("#linkAddress").val();
        //联系电话
        var linkPhone = $("#linkPhone").val();

        //材料附件集合
        var manifests=new Array();
        $("input[name='manifest_data']").each(function(index,obj){
            manifests.push({
                guid:$(obj).attr("guid"),
                matMId:$(obj).attr("matMId"),
                fileRealName:$(obj).attr("filename")
            });
        });
        //申报方式
        var netProjectType = 'PCP';

        //申报来源 本系统传SYS
        var tskSource = "SYS";

        //邮寄方式
        var isMailMertal='101';//暂时

        //邮寄地址上门 Guid
        var addressGuidSm=$('input[name="q-out"]').val();

        //邮寄地址送件 Guid
        var addressGuidSj;
        $.ajax({
            url: '<c:url value="/matters/ajax-project"></c:url>',
            type:"POST",
            data : JSON.stringify({
                "matNum" : matNum,
                "deptId":deptId,
                "accountId":acountId,
                "linkAddress":linkAddress,
                "linkPhone":linkPhone,
                "netProjectType":netProjectType,
                "tskSource":tskSource,
                isMailMertal:isMailMertal,
                addressGuidSm:addressGuidSm,
//                addressGuidSj:addressGuidSm,
                manifests:manifests
            }),
            dataType: "json",
            contentType: 'application/json;charset=utf-8',
            success: function (resp) {
                if(resp.succ){

                    $("#task_id").html("办件编号："+resp.data);
                    $("#chooseWay-dialog").modal("hide");
                    $('#way01-dialog').modal("hide");
                    $('#way02-dialog').modal("hide");
                    $('#waySuccess-dialog').modal();
                }else{
                    toast("服务器异常");
                }

            }
        })


    }

    function applyfileupload(manifestGuid){
        //alert(manifestGuid);
        $("#"+manifestGuid).fileupload({
            url: '<c:url value="/matters/ajax-att"/>',
            dataType: 'json',
            done: function (e, data) {
//                                                    console.info(data.result.data);
                if(data.result.succ==false){
                    layer.open({
                        content: data.result.msg,
                        scrollbar: false
                    });
                }else{
                    var attachBox = $('<div class="attach"><span>'+data.result.data.fileName+'</span><a href="javascript:;" class="delete" onclick="deleteFlie(this,\''+data.result.data.guid+'\');"></a><input filename="'+data.result.data.fileName+'" guid="'+data.result.data.guid+'" matMId="'+manifestGuid+'" name="manifest_data" type="hidden"/></div>')
                    attachBox.appendTo($(this).parents("li"));
                }

            }
        });
    }
</script>
</body>
</html>







